//
//  UIView+Property.m
//  RiceBasket
//
//  Created by DwZeng on 2021/1/15.
//

#import "UIView+Property.h"

@implementation UIView (Property)

+(UIView* (^)())init{
    return ^(){
        UIView *view = [[self alloc] init];
        return view;
    };
}

+(UIView *(^)(CGRect frame))initFrame{
    return ^(CGRect frame){
        UIView *view = [[self alloc] initWithFrame:frame];
        return view;
    };
}

-(UIView *(^)(NSString*))bgColor{
    return ^(NSString *colorStr){
        
        self.backgroundColor = [UIColor colorWithHexString:colorStr];
        return self;
    };
}

-(UIView *(^)(CGFloat alpha))setAlpha{
    return ^(CGFloat alpha){
        self.alpha = alpha;
        return self;
    };
}

-(UIView *(^)(BOOL hidden))setHidden{
    return ^(BOOL hidden){
        self.hidden = hidden;
        return self;
    };
}

//给view添加圆角
-(void)addCorners:(UIRectCorner)corners cornerRadii:(CGSize)size{
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:size];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.bounds;
    maskLayer.path = maskPath.CGPath;
    self.layer.mask = maskLayer;
}

+(UIVisualEffectView *)effectView:(CGRect)frame{
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    effectView.frame = frame;
    return effectView;
}

@end
